package com.aimee.table;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.aimee.table.adapter.FruitAdapter;
import com.aimee.table.bean.Fruit;
import com.aimee.table.util.DpTool;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.lv_table)
    ListView lvTable;

    private FruitAdapter fruitAdapter;

    private List<Fruit> fruitList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {

        lvTable.setDivider(new ColorDrawable(Color.BLACK));
        lvTable.setDividerHeight(DpTool.dp2px(this, 1));

        fruitList.add(new Fruit()); // 表头
        fruitList.add(new Fruit("苹果", "1", "10"));
        fruitList.add(new Fruit("梨", "2", "6"));
        fruitList.add(new Fruit("橙子", "5", "13"));
        fruitAdapter = new FruitAdapter(this, fruitList);
        lvTable.setAdapter(fruitAdapter);
    }
}
